<?php

namespace app\admin\model\pifa;

use think\Model;
use fast\AdapayUtil;
use think\Exception;
class Shangjia extends Model
{

    

    

    // 表名
    protected $name = 'pifa_shangjia';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text'
    ];
    
    protected static function init()
    {
        


     

        self::beforeInsert(function ($row) {
            

            

        });

        self::beforeWrite(function ($row) {
          

            if (!empty($row['chengshi'])) {
               $data = explode('/', $row['chengshi']);

                if (isset($data[0]) &&  !empty($data[0])) {
                   $row['province'] = $data[0];
                }
                if (isset($data[1]) &&  !empty($data[1])) {
                   $row['city'] = $data[1];
                }
                if (isset($data[2]) &&  !empty($data[2])) {
                   $row['area'] = $data[2];
                }

              
            }
            
        });
    }

    
    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
